# -*- coding: utf-8 -*-
# @Time    : 2025/9/19 11:20
# @Author  : chenmh
# @File    : config.py
# @Desc: 自定义配置类，提供多种使用方式
from sympy.codegen.ast import continue_


class BSTConfig:
    def __init__(self, **kwargs):
        """
        初始化时接收任意关键字参数作为属性
        """
        # 初始化内部存储字典
        self._data = {}
        # 将传入的关键字参数设置为属性（会自动调用 __setattr__）
        for key, value in kwargs.items():
            setattr(self, key, value)

    def __getattr__(self, name):
        """
        当点号访问的属性不存在时，尝试从 _data 中查找
        """
        try:
            return self._data[name]
        except KeyError:
            raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")

    def __setattr__(self, name, value):
        """
        设置属性时，非 '_data' 本身的属性都存入 _data
        """
        if name == '_data':
            # 初始化 _data 时，直接设置
            super().__setattr__(name, value)
        else:
            # 其他所有属性都存入 _data
            self._data[name] = value

    def __getitem__(self, key):
        """支持 A['key'] 访问"""
        return self._data[key]

    def __setitem__(self, key, value):
        """支持 A['key'] = value 设置"""
        self._data[key] = value

    def __delitem__(self, key):
        """支持 del A['key']"""
        del self._data[key]

    def __delattr__(self, name):
        """支持 del A.name"""
        try:
            del self._data[name]
        except KeyError:
            raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")

    def __contains__(self, key):
        """支持 'key' in A"""
        return key in self._data

    def __repr__(self):
        return f"{self.__class__.__name__}({self._data})"


bst_config = BSTConfig(
    seq_len=200
    , hidden_size=256
    , n_layers=4
    , n_heads=8
    , dropout=0.2
    , learning_rate=1e-5
    , batch_size=8
    , vocab_size=200
    , pad_token_id=0
    , max_position_embeddings=256
    , type_vocab_size=2
    , layer_norm_eps=1e-12
    , hidden_dropout_prob=0.1
    # 配置静态属性的 embedding 这里先瞎写几个
    , static_embeddings_vocab_size=[20, 30, 10]
    # , num_static_features=3  # 静态属性数量
    , feedforward_size=1024
    , warmup_steps_rate=0.1
    , patience=5
    , best_model_name="transformer_static_model"
    , save_path="./logs/"
    , num_epochs=1
    , is_continued_train=False  # 断点续训
    , continued_timestamp=""
    , early_stop_metric="auc"
)
